jsx3.Class.defineClass(
        "tibco.admin.monitormanage.uicomponents.text.serviceInstanceHeader.ServiceInstanceHeader", //the full name of the class to create
        jsx3.gui.Block, //  extends
        null, // implements
        function (plugin) {
            plugin.prototype.contentLoaded = false;
        
            plugin.prototype.init = function() {
                this.jsxsuper();
            }
            
            plugin.prototype.getNamespace = function() {
               return "tibco.admin";
            }
            
            plugin.prototype.setUpComponent = function() {
            	this.contentLoaded = false;
            	// this next nastiness is due to the asynchronous nature of the environment
            	// First try to load the info and see if the cache is ready...if not the
            	// page bus will send a message when the cache is ready.
            	var subject = tibco.admin.monitormanage.uicomponents.page.serviceView.ServiceView.serviceInstanceInfoCacheSubject;
            	tibco.admin.monitormanage.general.PageBusUtils.subscribe(subject, this.loadContent, this);
            	this.loadContent(null, null, this);
            }
            
            plugin.prototype.loadContent = function(subject, message, headerObj) {
            	if(!headerObj.contentLoaded)
            	{
            		var serviceInfoDoc = tibco.admin.Main.getServer().Cache.getDocument(tibco.admin.monitormanage.uicomponents.page.serviceView.ServiceView.serviceInstanceInfoCacheId);
           		 	if(serviceInfoDoc)
           		 	{
            			headerObj.contentLoaded = true;
            			var server = tibco.admin.Main.getServer();
            			var record = serviceInfoDoc.getFirstChild();
            			
            			var nameField = headerObj.getDescendantOfName("serviceInstanceNameLabel");
            			nameField.setText(record.getAttribute("name"));
            			nameField.repaint();
            			
            			var onNodeField = headerObj.getDescendantOfName("onNodeLabel");
            			var onNodeText = server.getDynamicProperty("@MM@general@onLabel") + record.getAttribute("nodeName");
            			onNodeField.setText(onNodeText);
            			onNodeField.repaint();
            			
            			var viewField = headerObj.getDescendantOfName("viewServiceOnNodesLabel");
            			var linkText = server.getDynamicProperty("@MM@general@viewServiceOnNodesLabel");
            			
            			// retrieve the service id from the service instance id which will be in the form <service id>/<node id>
            			var serviceInstanceId = record.getAttribute("key");
            			var serviceId = serviceInstanceId;
            			var slashIdx = serviceId.indexOf("/");
            			if(slashIdx != -1)
            			{ serviceId = serviceId.substring(0, slashIdx); }
            			
            			var viewText = " <a href=\"javascript:tibco.admin.monitormanage.uicomponents.text.serviceInstanceHeader.ServiceInstanceHeader.showServiceDetail('" + serviceId + "');\">" + linkText + "</a>";
            			viewField.setText(viewText);
            			viewField.repaint();
            		}
            	}
            }
            
            plugin.showServiceDetail = function(serviceIdVal) {
        		var paramArray = { serviceId:serviceIdVal };
        		tibco.admin.monitormanage.general.NavigationHandler.publishMainPageNavigationMessage(tibco.admin.monitormanage.uicomponents.page.serviceView.ServiceView.serviceScreenId, paramArray); 
        	}
            
        });